package com.woniuxy.microretailserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microretailserver.bean.OrderGoodsBean;
import com.woniuxy.microretailserver.bean.PageRequest;
import com.woniuxy.microretailserver.mapper.OrderGoodsMapper;
import com.woniuxy.microretailserver.service.IOrderGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Transactional(readOnly = true)
@Service
public class OrderGoodsServiceImpl implements IOrderGoodsService {

    @Resource
    private OrderGoodsMapper orderGoodsMapper;

    /**
     * 分页查询订单和商品信息
     * @param request
     * @param orderGoodsBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public PageInfo<OrderGoodsBean> findPageOrder(PageRequest request, OrderGoodsBean orderGoodsBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->orderGoodsMapper.findPageOrder(request, orderGoodsBean));
    }
}
